#coding=UTF-8 
from chinacQA.Static import testEnvtConf
from chinacQA.TestCase import TestCase
from chinacQA.TestLink_TestCase import assertBool
from chinacQA.TestLink_TestCase import getConfigure_ENG
from chinacQA.TestLink_TestCase import waitMoment
from chinacQA.Functional import MoveToElement

from template.NeoCUUI_ENG import *
from TC_100_NeoCU_Language import STEP_AdminLoginAndChangeLanguage

def Login(user, pw):
    idusername.text=user
    idpassword.text=pw
    loginBtn.click()

def CreateServer():
    ComputeMenu_01.click()
    Menu_Server_p.click()
    instances_action_launch.click()
    name.text =getConfigure_ENG("Server_name")
    instancecount.text = getConfigure_ENG("Server_Count")
    flavorstype.select(text=getConfigure_ENG("Server_flavorstype"))
    flavor.select('6')
    sourcetype.select(text=getConfigure_ENG("Server_sourcetype"))
    souceimages.select(text=testEnvtConf.Images)
    textContent.text = getConfigure_ENG("Server_textContent")
    NextButton.click()
    sn.select(text=getConfigure_ENG("net"))
    ssn.select(index=1)
    NextButton2.click()
    #kpcheck.uncheck()
    #pswdcheck.check()
    adminpassword.text = getConfigure_ENG("Server_adminpassword")
    #SecuritySetup.click()
    CreateButton.click()
    waitMoment(10)
    
def checkSuccess(hopeStatus,id):
    Menu_Server1.click()  
    heads = instances.getHeads()
    column = heads.index('Status')
    status = False
    for i in range(200):
        waitMoment(6)
        if (instances.getStatusCell(0,column) ==hopeStatus):
            status = True
            break
        
    assertBool(status,id)
    
def STEP_createPrivateNet():
    NetworkMenu_tab_n.click()
    PrivateNetMenu.click()
    networks_action_create.click()
    idname_privateNET.text=getConfigure_ENG("net")
    privateSubmit.click()
    
    heads = networksTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    for i in range(len(networksTable.getRows())):
        if(networksTable.getCell(i,columnName).text==getConfigure_ENG("net")):
            actioncell=networksTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.find_element("xpath",".//a").text.strip()=="Add Subnet"):
                    button.click()
                    idsubnet_name.text = getConfigure_ENG("subnet")
                    idcidr.text = getConfigure_ENG("idcidr")
                    idgateway_ip.text = getConfigure_ENG("idgateway_ip")
                    SubDetailTab.click()
                    idallocation_pools.text = getConfigure_ENG("Addresspools")
                    createNet.click()
                    assertBool(True,"3375")
                    break
                
def STEP_createCinder():
    StorangeMenu_tab.click()
    CinderMenu.click()
    volumes_action_create.click()
    Cinderidname.text=getConfigure_ENG("CinderName")
    iddescription.text=getConfigure_ENG("CinderDes")
    idsize.text=getConfigure_ENG("CinderSize")
    CreateCinderButton.click()
    heads = volumeTable.getHeads()
    columnName = heads.index('Name')
#     columnAction = heads.index('Actions')
    for i in range(len(volumeTable.getRows())):
        if(volumeTable.getCell(i,columnName).text==getConfigure_ENG("CinderName")):
            assertBool(True,"3343")
            return
    assertBool(False,"3343")        
            
def STEP_CheckServerDeleteFunction():
    ComputeMenu_01.click()
    Menu_Server_p.click()
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
#     columnAction = heads.index('Actions')
    if("No items to display." in instances.getCell(0,0).text):
        return
    for i in range(len(instances.getRows())):
        actioncell=instances.getCell(i,0)
        menu_ul = actioncell.find_element("xpath",".//label")
        menu_ul.click()
        
    ServerMoreActionButton.click()
    Serinstances_action_delete.click()
    waitMoment(6)
    DeleteServerButton.click()
    status = False
    for i in range(100):
        Menu_Server_p.click()
        if(len(instances.getRows())>0):
            if ("No items to display." in instances.getCell(0,0).text.strip()):
                status = True
                break
        else:
            status = True
            break
        if(status):
            break                
    assertBool(status,"3323")

def STEP_CheckServerEditFunction():
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_name")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Modify Name"):
                    button.click()
                    Server_editname.text=getConfigure_ENG("Server_Newname")
                    saveEditServer.click()
                    break
    status = False
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName)!=None and instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            status = True
    assertBool(status,"3283")

def STEP_CheckServerOpenConsoleFunction():
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Console"):
                    button.click()
                    break
    waitMoment(6)
    assertBool(MainPage1.windows(getConfigure_ENG("Server_Newname")),"3285")
    MainPage1.windowClose(getConfigure_ENG("Server_Newname"))
               
def STEP_CheckServerCloseFunction():
    #waitMoment(5)
    #ComputeMenu_01.click()
    Menu_Server_p.click()
    waitMoment(5)
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            waitMoment(3)
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Shut Down Instance"):
                    button.click()
                    closeServer.click()
                    status = True
                    break
    checkSuccess("Shutdown","3287")

def STEP_CheckServerOpenFunction():
    #ComputeMenu_01.click()
    Menu_Server_p.click()
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Start Instance"):
                    button.click()
                    break
    checkSuccess("Active","3289")

def STEP_Check2ServerOpenFunction():
    ComputeMenu_01.click()
    Menu_Server_p.click()
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Start Instance"):
                    button.click()
                    break
    checkSuccess("Active","3289")
    
def STEP_CheckServerTemplateFunction():
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            ServerMoreAction(menu_ul,'Other','Create Image')
            Template_idname.text=getConfigure_ENG("Template_name")
            #Template_check.click()
            TemplateConfirmButton.click()
            break
                  
    status0 = False
    status1 = False
    for i in range(200):
        Menu_Server_p.click()
        heads = instances.getHeads()
        column = heads.index('Status')
        if (instances.getStatusCell(0,column) =="Image Creating"):
            status0 =True
        elif (instances.getStatusCell(0,column) =="Shutdown"):
            status1 = True
            break
        
    assertBool(status1,"3291")

def ServerMoreAction(element,action,subaction): 
    menubuttons = element.find_elements("xpath",".//li")
    for button in menubuttons:
        if (button.text.strip()==action):
            MoveToElement(button)
            waitMoment(2)
            subbuttons = button.find_elements("xpath",".//li")
            for subbutton in subbuttons:
                if (subbutton.text.strip()==subaction):
                    subbutton.click()
                    break
            break
    
def STEP_CheckServerSnapshotFunction():
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            ServerMoreAction(menu_ul,'Other','Create Snapshot')
            Snapshotidname.text=getConfigure_ENG("SnapShot_name")
            SnapshotCreate.click()
          
    status0 = False
    status1 = False
    for i in range(200):
        try:
            Menu_Server_p.click()
        except Exception,e:
            print e
        heads = instances.getHeads()
        column = heads.index('Status')
        if (instances.getStatusCell(0,column) =="Image Creating"):
            status0 =True
        elif (instances.getStatusCell(0,column) =="Shutdown"):
            status1 = True
            break
        
    assertBool(status1,"3293")
    
def STEP_CheckServerHotUpgradeFunction():
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="热升级"):
                    button.click()
                    idold_flavor_vcpus.text=getConfigure_ENG("Hot_cpu")
                    idold_flavor_mem.text=getConfigure_ENG("Hot_mem")
                    HotUpgrateButton.click()
                    break
                
def STEP_CheckServerModifyPWFunction():
    waitMoment(30)
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Change Password"):
                    button.click()
                    idadmin_pass.text=getConfigure_ENG("ServerNewPW")
                    ModifyPWButton.click()
                    break
    assertBool(True,"3303")
           
def STEP_CheckServerSoftRebootFunction():
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Soft Reboot Instance"):
                    button.click()
                    SoftRebootButton.click()
                    break
                
    status0 = False
    for i in range(200):
        waitMoment(2)
        try:
            Menu_Server_p.click()
        except Exception,e:
            print e
        waitMoment(2)
        heads = instances.getHeads()
        column = heads.index('Status')
        if (instances.getStatusCell(0,column) =="Active"):
            status0 =True
            break

    assertBool(status0,"3311")

def STEP_CheckServerHardRebootFunction():
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Hard Reboot Instance"):
                    button.click()
                    HardRebootButton.click()
                    break
                
    status0 = False
    for i in range(200):
        heads = instances.getHeads()
        column = heads.index('Status')
        if (instances.getStatusCell(0,column) =="Active"):
            status0 =True
            break

    assertBool(status0,"3305")
    
def STEP_CheckServerConnectCinderFunction():
    heads = instances.getHeads()
    columnName = heads.index('Instance Name')
    columnAction = heads.index('Actions')
    for i in range(len(instances.getRows())):
        if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
            actioncell=instances.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            ServerMoreAction(menu_ul,'Resource','Attach Volume')
            ChooseCinderButton.click()
            menubuttons = ChooseCinderButton.element.find_elements("xpath",".//li")
            for buttonm in menubuttons:
                if (getConfigure_ENG("CinderName") in buttonm.text.strip()):
                    buttonm.click()
                    ConnectCinderButton.click()
                    assertBool(True,"3317")
                    return 
    assertBool(False,"3317")
    
def STEP_SnapshotCreateServer():
    Menu_Snapshot.click()
    heads = vmsnapshot.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    for i in range(len(vmsnapshot.getRows())):
        if(vmsnapshot.getCell(i,columnName).text==getConfigure_ENG("SnapShot_name")):
            actioncell=vmsnapshot.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="创建云主机"):
                    button.click()
                    break
    waitMoment(3)
    SnapShotCreatename.text = getConfigure_ENG("SnapshotServer_name")
    SnapShotinstancecount.text = getConfigure_ENG("SnapshotServer_Count")
    Snapshotflavorstype.select(text=getConfigure_ENG("SnapshotServer_flavorstype"))
    waitMoment(10)
    Snapshotflavor.select('6')

    SnapshottextContent.text = getConfigure_ENG("SnapshotServer_textContent")
    SnapshotNext1.click()
    Snapshotsn.select(text=getConfigure_ENG("net"))
    Snapshotssn.select(index=1)
    SnapshotNext2.click()
    #Snapshotkpcheck.uncheck()
    #Snapshotpswdcheck.check()
    Snapshotadminpassword.text = getConfigure_ENG("SnapshotServer_adminpassword")
    SnapshotCreateButton.click()
    waitMoment(3)

    Menu_Server1.click() 
    for i in range(200): 
        waitMoment(3)
        heads = instances.getHeads()
        columnName = heads.index('Instance Name')
        columnAction = heads.index('Status')
        for i in range(len(instances.getRows())):
            if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("SnapshotServer_name")):
                if(instances.getCell(i,columnAction).text.strip() == "Active"):
                    assertBool(True,"3329")
                    return 
    
    assertBool(False,"3329")

def STEP_SnapshotRollback():
    Menu_Snapshot.click()
    heads = vmsnapshot.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    for i in range(len(vmsnapshot.getRows())):
        if(vmsnapshot.getCell(i,columnName).text==getConfigure_ENG("SnapShot_name")):
            actioncell=vmsnapshot.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Snapshot Rollback"):
                    button.click()
                    break
    SnapshotRollBackButton.click()
    waitMoment(6)

    Menu_Server1.click() 
    for i in range(200): 
        waitMoment(3)
        heads = instances.getHeads()
        columnName = heads.index('Instance Name')
        columnAction = heads.index('Status')
        for i in range(len(instances.getRows())):
            if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
                if(instances.getCell(i,columnAction).text.strip() == "Shutdown"):
                    assertBool(True,"3325")
                    return 
    
    assertBool(False,"3325")

def STEP_TemplateCreate():
    Menu_Template.click()
    waitMoment(2)
    images_action_customize.click()
    ImageCreateidname.text = getConfigure_ENG("Template_CreateName")
    
    ChooseImageServer.click()
    menus = ChooseImageServer.element.find_elements("xpath",".//li")
    for buttonm in menus:
        if (getConfigure_ENG("Server_Newname") in buttonm.text.strip()):
            buttonm.click()
            break
    Imageiddescription.text = getConfigure_ENG("Template_CreateDec")
    ImageCreateCommit.click()
    
    waitMoment(3) 
    status1 = False 
    for i in range(200):
        try:
            Menu_Server1.click() 
        except Exception,e:
            print e 
        waitMoment(5)
        heads = instances.getHeads()
        columnName = heads.index('Instance Name')
        columnStatus = heads.index('Status')
        for i in range(len(instances.getRows())):
            if (instances.getCell(i,columnName) != None and instances.getCell(i,columnName).text.strip()== getConfigure_ENG("Server_Newname")):
                if (instances.getStatusCell(i,columnStatus) =="Shutdown"):
                    status1 = True
                    break
        if(status1):
            break
                
    assertBool(status1,"3331")
    waitMoment(2)

def STEP_TemplateEdit():
    Menu_Template.click()
    heads = imagesTable.getHeads()
    columnName = heads.index('Image Name')
    columnAction = heads.index('Actions')
#     print len(imagesTable.getRows())
    for i in range(len(imagesTable.getRows())):
        if(imagesTable.getCell(i,columnName).text.strip()==getConfigure_ENG("Template_CreateName")):
            actioncell=imagesTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Edit"):
                    button.click()
                    Imageidname.text = getConfigure_ENG("Template_Newname")
                    Imageiddescription.text = getConfigure_ENG("Template_Dec")
                    #selectOSInImage.select(text=getConfigure_ENG("ImageServer_flavorstype"))
                    id_os_type_chosen.click()
                    menus = id_os_type_chosen.element.find_elements("xpath",".//li")
                    for buttonm in menus:
                        if (getConfigure_ENG("Template_OSType") in buttonm.text.strip()):
                            buttonm.click()
                            break
                    imageSave.click()
                    break
   
    status = False
    waitMoment(3)
    for i in range(len(imagesTable.getRows())):
        if (imagesTable.getCell(i,columnName)!=None and imagesTable.getCell(i,columnName).text.strip()== getConfigure_ENG("Template_Newname")):
            status = True
            break
    assertBool(status,"3337")

def STEP_TemplateCreateServer():
    Menu_Template.click()
    heads = imagesTable.getHeads()
    columnName = heads.index('Image Name')
    columnAction = heads.index('Actions')
    for i in range(len(imagesTable.getRows())):
        if(imagesTable.getCell(i,columnName).text.strip()==getConfigure_ENG("Template_Newname")):
            actioncell=imagesTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Create Instance"):				
                    button.click()
                    break
   
    ImageCreateServername.text = getConfigure_ENG("ImageServer_name")
    ImageCreateinstancecount.text = getConfigure_ENG("ImageServer_Count")
    Imageflavorstype.select(text=getConfigure_ENG("ImageServer_flavorstype"))
    waitMoment(1)
#     Imageflavor.select(text=getConfigure_ENG("ImageServer_flavor"))
    Imageflavor.select('6')
    ImagetextContent.text = getConfigure_ENG("ImageServer_textContent")
    ImageNext1.click()
    waitMoment(3)
    Imagesn.select(text=getConfigure_ENG("net"))
    Imagessn.select(index=1)
    ImageNext2.click()
    #Imagekpcheck.uncheck()
    #Imagepswdcheck.check()
    Imageadminpassword.text = getConfigure_ENG("ImageServer_adminpassword")
    ImageCreateButton.click()
    waitMoment(5)
    Menu_Server1.click() 
    for i in range(200): 
        waitMoment(5)
        heads = instances.getHeads()
        columnName = heads.index('Instance Name')
        columnAction = heads.index('Status')
        for i in range(len(instances.getRows())):
            if (instances.getCell(i,columnName).text.strip()== getConfigure_ENG("ImageServer_name")):
                if(instances.getCell(i,columnAction).text.strip() == "Active"):
                    assertBool(True,"3339")
                    return 
    
    assertBool(False,"3339")

def STEP_TemplateCreateCinder():
    Menu_Template.click()
    heads = imagesTable.getHeads()
    columnName = heads.index('Image Name')
    columnAction = heads.index('Actions')
    for i in range(len(imagesTable.getRows())):
        if(imagesTable.getCell(i,columnName).text==getConfigure_ENG("Template_Newname")):
            actioncell=imagesTable.getCell(i,columnAction)
            menu_ul = actioncell.find_element("xpath",".//div")
            menu_ul.click()
            menubuttons = menu_ul.find_elements("xpath",".//li")
            for button in menubuttons:
                if (button.text.strip()=="Create Volume"):
                    button.click()
                    break
                
    ImageCinderidname.text = getConfigure_ENG("ImageCinder_name")
    ImageCinderiddescription.text = getConfigure_ENG("ImageCider_dec")
    ImageCinderidsize.text = getConfigure_ENG("ImageCinder_size")
    ImageCreateCinderButton.click()
    
    CinderMenu.click()
    heads = volumeTable.getHeads()
    columnName = heads.index('Name')
#     columnAction = heads.index('Actions')
    for i in range(len(volumeTable.getRows())):
        if(volumeTable.getCell(i,columnName).text==getConfigure_ENG("ImageCinder_name")):
            assertBool(True,"3341")
            return
    assertBool(False,"3341") 
    
def STEP_deletePriNet():
    NetworkMenu_tab_n.click()
    PrivateNetMenu.click()
    heads = networksTable.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    if("No items to display." in networksTable.getCell(0,0).text):
        assertBool(False,"3381")
        return
    for i in range(len(networksTable.getRows())):
        actioncell=networksTable.getCell(i,0)
        menu_ul = actioncell.find_element("xpath",".//label")
        menu_ul.click()
    
    networks_action_delete_net.click()
    deletepriNet.click()    
     
    status = False
    for i in range(100):
        PrivateNetMenu.click()
        waitMoment(3)
        if("No items to display." in networksTable.getCell(0,0).text.strip()):
            status = True
            break
    assertBool(status,"3381")

def STEP_deleteSnapshot():
    ComputeMenu_01.click()
    Menu_Snapshot.click()
    heads = vmsnapshot.getHeads()
    columnName = heads.index('Name')
    columnAction = heads.index('Actions')
    if("No items to display." in vmsnapshot.getCell(0,0).text):
        return
    for i in range(len(vmsnapshot.getRows())):
        actioncell=vmsnapshot.getCell(i,0)
        menu_ul = actioncell.find_element("xpath",".//label")
        menu_ul.click()
    vmsnapshot_action_delete.click()
    ServerSnapShotDelete.click()
    
    status = False
    for i in range(100):
        Menu_Snapshot.click()
        waitMoment(3)
        if("No items to display." in vmsnapshot.getCell(0,0).text.strip()):
            status = True
            break
    assertBool(status,"3327")
               
def STEP_deleteTemplate():
    ComputeMenu_01.click()
    Menu_Template.click()
    heads = imagesTable.getHeads()
    columnName = heads.index('Image Name')
    columnAction = heads.index('Actions')
    if("No items to display." in imagesTable.getCell(0,0).text):
        return
    for i in range(len(imagesTable.getRows())):
        actioncell=imagesTable.getCell(i,0)
        menu_ul = actioncell.find_element("xpath",".//label")
        menu_ul.click()
    
    images_action_delete.click()
    waitMoment(6)
    imageDeleteCommit.click()
    
    status = False
    for i in range(100):
        Menu_Template.click()
        waitMoment(10)
        if("No items to display." in imagesTable.getCell(0,0).text.strip()):
            status = True
            break
              
    assertBool(status,"3335")
       
def STEP_deleteCinder():
    StorangeMenu_tab.click()
    CinderMenu.click()
    if("No items to display." in volumeTable.getCell(0,0).text):
        assertBool(False,"3357")
        return
    for i in range(len(volumeTable.getRows())):
        actioncell=volumeTable.getCell(i,0)
        menu_ul = actioncell.find_element("xpath",".//label")
        menu_ul.click()
 
    volumes_action_delete.click() 
    waitMoment(6)
    DeleteCinderButton.click() 
    
    status = False
    for i in range(100):
        waitMoment(3)
        CinderMenu.click()
        if(len(volumeTable.getRows())>0):
            if ("No items to display." in volumeTable.getCell(0,0).text.strip()):
                status = True
                break
        else:
            status = True
            break
        if(status):
            break                
    assertBool(status,"3357")

def STEP_deleteRubbish():
    RubbishMenu.click()
    if("No items to display." in volumerecycleTable.getCell(0,0).text):
        return
    for i in range(len(volumerecycleTable.getRows())):
        actioncell=volumerecycleTable.getCell(i,0)
        menu_ul = actioncell.find_element("xpath",".//label")
        menu_ul.click()
        
    volumerecycle__action_delete.click()    
    waitMoment(8)
    RubbishDeleteButton.click()
    status = False
    for i in range(100):
        waitMoment(3)
        RubbishMenu.click()
        if(len(volumerecycleTable.getRows())>0):
            if ("No items to display." in volumerecycleTable.getCell(0,0).text.strip()):
                status = True
                break
        else:
            status = True
            break
        if(status):
            break                
    assertBool(status,"3477")

def logonOut():
    adminrole.click()
    waitMoment(1)
    loginout.click()

# def deleteProAndUser():
#     BusinessManager.click()
#     ManagerInfo.click()
# 
#     heads = tenants.getHeads()
#     columnName = heads.index('Name')
#     columnAction = heads.index('Actions')
#     for i in range(len(tenants.getRows())):
#         if(tenants.getCell(i,columnName)!=None and tenants.getCell(i,columnName).text.strip()==getConfigure_ENG("ProjectName")):
#             actioncell=tenants.getCell(i,columnAction)
#             menu_ul = actioncell.find_element("xpath",".//div")
#             menu_ul.click()
#             menubuttons = menu_ul.find_elements("xpath",".//ul/li")
#             for button in menubuttons:
#                 if (button.text.strip()=="删除"):
#                     button.click()
#                     deletePro.click()
#                     break
#     UserManager.click()
#     heads = userstable.getHeads()
#     columnName = heads.index('登录名')
#     columnAction = heads.index('Actions')
#     for i in range(len(userstable.getRows())):
#         if(userstable.getCell(i,columnName).text.strip()==getConfigure_ENG("User")):
#             actioncell=userstable.getCell(i,columnAction)
#             menu_ul = actioncell.find_element("xpath",".//div")
#             menu_ul.click()
#             menubuttons = menu_ul.find_elements("xpath",".//li")
#             for button in menubuttons:
#                 if (button.text.strip()=="删除"):
#                     button.click()
#                     deleteuser.click()
#                     break

def STEP_UserLogin():
    Login(getConfigure_ENG("User"),getConfigure_ENG("UserNewPassword"))

def STEP_CreateServer():
    CreateServer()
    checkSuccess("Active",'3281')
    
def STEP_Clean():
    logonOut()

TC_106_NeoCUServer  = TestCase("Neocu ENG Server")
TC_106_NeoCUServer.AddStep(STEP_AdminLoginAndChangeLanguage)
TC_106_NeoCUServer.AddStep(STEP_UserLogin)
TC_106_NeoCUServer.AddStep(STEP_createPrivateNet)
TC_106_NeoCUServer.AddStep(STEP_createCinder)
TC_106_NeoCUServer.AddStep(STEP_CreateServer)
TC_106_NeoCUServer.AddStep(STEP_CheckServerEditFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerOpenConsoleFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerCloseFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerOpenFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerCloseFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerTemplateFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerSnapshotFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerOpenFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerModifyPWFunction)  
TC_106_NeoCUServer.AddStep(STEP_CheckServerSoftRebootFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerHardRebootFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerConnectCinderFunction)
TC_106_NeoCUServer.AddStep(STEP_CheckServerCloseFunction)
TC_106_NeoCUServer.AddStep(STEP_SnapshotRollback)
#TC_106_NeoCUServer.AddStep(STEP_CheckServerCloseFunction)
TC_106_NeoCUServer.AddStep(STEP_TemplateCreate)
TC_106_NeoCUServer.AddStep(STEP_TemplateEdit)
TC_106_NeoCUServer.AddStep(STEP_TemplateCreateServer)
TC_106_NeoCUServer.AddStep(STEP_TemplateCreateCinder)
TC_106_NeoCUServer.AddStep(STEP_Check2ServerOpenFunction)
# TC_106_NeoCUServer.AddStep(STEP_deleteSnapshot)
# TC_106_NeoCUServer.AddStep(STEP_CheckServerDeleteFunction)
# TC_106_NeoCUServer.AddStep(STEP_deletePriNet)
# TC_106_NeoCUServer.AddStep(STEP_deleteCinder)
# TC_106_NeoCUServer.AddStep(STEP_deleteRubbish)
# TC_106_NeoCUServer.AddStep(STEP_deleteTemplate)
TC_106_NeoCUServer.AddStep(STEP_Clean)


if __name__ == "__main__":
    TC_106_NeoCUServer.run()
